#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main()
{
    string s;
    cin >> s;
    cerr << s.size() << "," << s << endl;
    int min = 1000;
    vector<vector<bool>> dp(s.size(), vector<bool>(s.size()));
    for (int i = s.size() - 1;i >= 0;i--)
    {
        for (int j = s.size();j >= i;j--)
        {
            if (s[i] == s[j])
            {
                if (i == j || j - i == 1) dp[i][j] = true;
                else dp[i][j] = dp[i + 1][j - 1];
            }
            else dp[i][j] = false;
            if (j - i + 1 > 1 && dp[i][j] == true && j - i + 1 < min)
            {
                cerr << "[" << i << "," << j << "]" << endl;
                for (int k = i;k <= j;k++) cerr << s[k] << " ";
                cerr << endl;
                min = j - i + 1;
            }
        }
    }
    // for(auto a:dp)
    // {
    //     for(auto b:a)
    //     {
    //         cerr<<b<<" ";
    //     }
    //     cerr<<endl;
    // }
    cerr << "max=" << min << endl;
    if (min == 1000) cout << "-1" << endl;
    else cout << min << endl;
    return 0;
}
